package com.javabasic.algorithm.leetcode;

public class InvertBinaryTree {

    public TreeNode invertTree(TreeNode root) {
        reverseTree(root);
        return root;
    }

    public void reverseTree(TreeNode root) {
        if (root != null) {
            reverseTree(root.right);
            reverseTree(root.left);
            TreeNode temp = root.right;
            root.right = root.left;
            root.left = temp;
        }
    }
}
class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;
    TreeNode(int x) { val = x; }
    TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }
}